<?php

namespace App\Admin\Forms;

use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class CourseComment extends Form implements LazyRenderable
{
    use LazyWidget;

    public function handle($input)
    {
        $id = $this->payload['id'];
        $status = $input['status'];

        if (!in_array($status, [1, 2])) return $this->response()->error('状态参数错误');

        $info = \App\Models\CourseComment::find($id);

        if (!$info) return $this->response()->error('信息不存在');
        if ($info->status) return $this->response()->error('该评论已审核');

        $info->update(['status' => $status]);

        return $this->response()->success('审核成功')->refresh();
    }

    public function form()
    {
        $payload = $this->payload;

        $this->text('content', '内容')->value($payload['content'] ?? '')->disable();
        $this->radio('status', '审核')->options([1 => '通过', 2 => '驳回']);
    }
}
